<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="apple-itunes-app" content="app-id=1052117670" />
    <style>
        button {
            position: fixed;
            top: 100px;
            left: 100px;
            width: 100px;
            height: 50px;
        }
    </style>
</head>
<body>
<button onclick="APPCommon.openApp()">打开App</button>
<script language="javascript">
    var APPCommon = {
        iphoneSchema: 'digitaling://open1?39783?http://file.digitaling.com/eImg/uimages/20170901/1504260781459851.jpg',
        iphoneDownUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.android.app.digitaling',
        androidSchema: 'digitaling://open?type=1&contentid=39783&cover=http://file.digitaling.com/eImg/uimages/20170901/1504260781459851.jpg',
        androidDownUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.android.app.digitaling',

        openApp: function(){
            var this_  =  this;
            //微信
            var version = navigator.userAgent.match(/os\s+(\d+)/i)[1] - 0;
            var isIphone = navigator.userAgent.match(/(iPhone|iPod|iPad);?/i);
            var isAndroid = navigator.userAgent.match(/android/i);
            if (isIphone && version >= 9) {
                //使用通用链接跳转（连接 路径 为 下载页路径， 后跟参数， 安装， 则跳转app，  未安装则跳转对应 通用连接 进行下载）
            } else {
                if (this_.isWeixin()) {
                    //提醒用户用系统浏览器打开
                } else {
                    if (isIphone) {
                        var loadDateTime = new Date();
                        window.setTimeout(function() {
                            var timeOutDateTime = new Date();
                            if (timeOutDateTime - loadDateTime < 5000) {
                                window.location = this_.iphoneDownUrl;//ios下载地址
                            } else {
                                window.close();
                            }
                        },25);
                        window.location = this.iphoneSchema;
                    } else if (isAndroid) {
                        try {
                            window.location = this_.androidSchema;

                            setTimeout(function(){
                                window.location=this_.androidDownUrl; //android下载地址
                            },500);
                        } catch(e) {}
                    } else {
                        //非iOS、Android 手机， 隐藏打开文章按钮
                    }
                }
            }
        },

        isWeixin: function(){ //判断是否是微信
            var ua = navigator.userAgent.toLowerCase();

            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true;
            } else {
                return false;
            }
        }
    };
</script>
</body>
</html>
